package com.yanqu.road.server.manager.activity.peakseacraft;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftActivityConfig;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaActivityConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.logic.bussiness.activity.PeakSeacraftBusiness;
import com.yanqu.road.logic.bussiness.activity.SeacraftSouthSeaBusiness;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.server.CrossBaseServer;
import com.yanqu.road.utils.date.DateHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description
 */
public class PeakSeacraftConfigMgr {

    private static Logger logger = LogManager.getLogger(PeakSeacraftConfigMgr.class.getName());

    private static Map<Integer, PeakSeacraftActivityConfig> configMap = new ConcurrentHashMap<>();

//    public static synchronized void reloadConfig(){
//        logger.info("start reload PeakSeacraft activity config  start");
//        String nowTimeStr = DateHelper.getCurrentDateTimeString();
//        List<Integer> activityTypeList = new ArrayList<>();
//        activityTypeList.add(eActivityType.PeakSeacraftActivity.getValue());
//
//        Map<Integer, ActivityInfo> activityInfoMap = ActivityBussiness.getOpenCrossRankActivityInfoMapByCrossServerId(activityTypeList, nowTimeStr, CrossBaseServer.getInstance().getServerId());
//        for (ActivityInfo item : activityInfoMap.values()){
//            reloadConfig(item);
//        }
//        logger.info("start reload PeakSeacraft activity config  end");
//    }

    public static synchronized PeakSeacraftActivityConfig reloadConfig(ActivityInfo activityInfo){
        List<Integer> activityIdList = new ArrayList<>();
        int activityId = activityInfo.getActivityId();
        activityIdList.add(activityId);
        Map<String, ActivityConfig> activityConfigMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(activityId);
        PeakSeacraftActivityConfig config = new PeakSeacraftActivityConfig(activityInfo);
        config.setShipList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaShipConfigList(activityId));
        config.setFloorList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaFloorConfigList(activityId));
        config.setBattleList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaBattleConfigList(activityId));
        config.setSilverDonateList(PeakSeacraftBusiness.getPeakSeacraftDonateConfigList(activityId));
        config.setRoundScoreMap(PeakSeacraftBusiness.getPeakSeacraftRoundScoreConfigList(activityId));
        config.setGuessList(PeakSeacraftBusiness.getPeakSeacraftLastGuessConfigList(activityId));
        config.parseConfig(activityConfigMap);
        configMap.put(activityId,config);
        return config;
    }


    public static Map<Integer, PeakSeacraftActivityConfig> getConfigMap() {
        return configMap;
    }

    public static void removeConfig(int activityId) {
        configMap.remove(activityId);
    }
}
